﻿package mortal.game.view.guildNew.mercenary
{
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.events.*;
    import extend.language.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.button.*;
    import mortal.game.view.guildNew.data.*;
    import mortal.mvc.core.*;

    public class GuildNewMercenaryTitle extends GSprite
    {
        protected var _bg:ScaleBitmap;
        protected var _btnSortByFightpower:SortButton;
        protected var _btnSortByLevel:SortButton;
        protected var _btnSortByTimes:SortButton;
        protected var _btnSortByOverTime:SortButton;
        protected var _btnSortByJob:SortButton;
        protected var _btnSortByUnit:SortButton;
        protected var _power:GTextFiled;
        protected var _nameTxt:GTextFiled;
        protected var _job:GTextFiled;
        protected var _level:GTextFiled;
        protected var _unit:GTextFiled;
        protected var _times:GTextFiled;
        protected var _oper:GTextFiled;
        protected var _overTime:GTextFiled;
        public var sortFunction:Function;

        public function GuildNewMercenaryTitle()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.bg(0, 0, 749, 23, this, ImagesConst.RegionTitleBg);
            this._power = UIFactory.gTextField("" + Language.getString(71547), 141, 1, 30, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._nameTxt = UIFactory.gTextField("" + Language.getString(71548), 36, 1, 70, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._job = UIFactory.gTextField("" + Language.getString(71549), 230, 1, 30, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._level = UIFactory.gTextField("" + Language.getString(71550), 308, 1, 30, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._unit = UIFactory.gTextField("" + Language.getString(71551), 383, 1, 55, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._times = UIFactory.gTextField("" + Language.getString(71552), 474, 1, 55, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._oper = UIFactory.gTextField("" + Language.getString(71553), 681, 1, 30, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._overTime = UIFactory.gTextField("" + Language.getString(71554), 575, 1, 55, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._btnSortByFightpower = UIFactory.sortButton(170, 5, this);
            this._btnSortByFightpower.configEventListener(SortEvent.DESCENDING, this.onSortChange);
            this._btnSortByFightpower.configEventListener(SortEvent.ASCENDING, this.onSortChange);
            this._btnSortByLevel = UIFactory.sortButton(339, 6, this);
            this._btnSortByLevel.configEventListener(SortEvent.DESCENDING, this.onSortChange);
            this._btnSortByLevel.configEventListener(SortEvent.ASCENDING, this.onSortChange);
            this._btnSortByTimes = UIFactory.sortButton(531, 5, this);
            this._btnSortByTimes.configEventListener(SortEvent.DESCENDING, this.onSortChange);
            this._btnSortByTimes.configEventListener(SortEvent.ASCENDING, this.onSortChange);
            this._btnSortByJob = UIFactory.sortButton(259, 5, this);
            this._btnSortByJob.configEventListener(SortEvent.DESCENDING, this.onSortChange);
            this._btnSortByJob.configEventListener(SortEvent.ASCENDING, this.onSortChange);
            this._btnSortByUnit = UIFactory.sortButton(437, 5, this);
            this._btnSortByUnit.configEventListener(SortEvent.DESCENDING, this.onSortChange);
            this._btnSortByUnit.configEventListener(SortEvent.ASCENDING, this.onSortChange);
            this._btnSortByOverTime = UIFactory.sortButton(634, 5, this);
            this._btnSortByOverTime.configEventListener(SortEvent.DESCENDING, this.onSortChange);
            this._btnSortByOverTime.configEventListener(SortEvent.ASCENDING, this.onSortChange);
            this.sortFunction = GuildUtil.constructMercenaryListSortFunc("combat", SortEvent.DESCENDING);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg = null;
            this._btnSortByFightpower = null;
            this._btnSortByLevel = null;
            this._btnSortByTimes = null;
            this._btnSortByOverTime = null;
            this._btnSortByJob = null;
            this._btnSortByUnit = null;
            this._power = null;
            this._nameTxt = null;
            this._job = null;
            this._level = null;
            this._unit = null;
            this._times = null;
            this._oper = null;
            this._overTime = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function onSortChange(event:SortEvent) : void
        {
            switch(event.target)
            {
                case this._btnSortByFightpower:
                {
                    this.sortFunction = GuildUtil.constructMercenaryListSortFunc("combat", event.type);
                    break;
                }
                case this._btnSortByJob:
                {
                    this.sortFunction = GuildUtil.constructMercenaryListSortFunc("level", event.type, true);
                    break;
                }
                case this._btnSortByLevel:
                {
                    this.sortFunction = GuildUtil.constructMercenaryListSortFunc("combat", event.type, true);
                    break;
                }
                case this._btnSortByUnit:
                {
                    this.sortFunction = GuildUtil.constructMercenaryListSortFunc("money", event.type);
                    break;
                }
                case this._btnSortByTimes:
                {
                    this.sortFunction = GuildUtil.constructMercenaryListSortFunc("count", event.type);
                    break;
                }
                case this._btnSortByOverTime:
                {
                    this.sortFunction = GuildUtil.constructMercenarySort3;
                    break;
                }
                default:
                {
                    break;
                }
            }
            Dispatcher.dispatchEvent(new DataEvent(GuildNewLocalEvent.GuildNewMercenaryUpdate));
            return;
        }// end function

    }
}
